home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10121 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Standard question - pointer initialization
  5. Date: 15 Mar 1996 18:06:46 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Mar15110646@qcd.lanl.gov>
  8. References: <4hk9un$906@hammer.msfc.nasa.gov> <4hl6rr$nde@news.xs4all.nl>
  9.     <313E6028.1C19@ix.netcom.com> <4hnpsl$g8c@hacgate2.hac.com>
  10.     <4hq9hsINN998@keats.ugrad.cs.ubc.ca> <4i7cgn$5da@baygull.rtd.com>
  11.     <TANMOY.96Mar13184413@qcd.lanl.gov> <3148D7DB.31C3@hawaii.edu>
  12. NNTP-Posting-Host: qcd.lanl.gov
  13. Mime-Version: 1.0
  14. Content-Type: text
  15. In-reply-to: Dave Carien's message of Thu, 14 Mar 1996 18:37:15 -0800
  16.  
  17. In article <3148D7DB.31C3@hawaii.edu>
  18. Dave Carien <davec@hawaii.edu> writes:
  19. <snip>
  20. DC: I was under the impression that NULL was a pointer type and to convert it 
  21.  
  22. The type of the macro NULL is not specified by the standard: NULL can
  23. only be used legally in contexts where the expected pointer type is
  24. already known.
  25.  
  26. Thus 
  27.  
  28. int i = NULL;        is wrong (int expected not pointer)
  29. int *i = NULL;       is okay (int * expected)
  30. printf("%p\n",NULL); is wrong (compiler does not know what type is
  31.                      expected in the varargs part of a function).
  32.  
  33. DC: to a char type it you would need to do something such as:
  34. DC: 
  35. DC: (char)NULL
  36. DC: 
  37.  
  38. (char)NULL is not a legal construct for all possible definitions of
  39. NULL. Thus NULL could be ((void*)0), in which case (char)NULL would
  40. try to convert a void* to a char. An implementation is free not to
  41. define such a conversion.
  42.  
  43. DC: Of course it would be wiser to use '\0', or just 0 for an int typecast.
  44.  
  45. Even if it is permitted, the implementation need not choose
  46. (char)(void*)0 to be the same as (char)0. 
  47.  
  48. And by the way, '\0' is an int in C (it is char in C++: but that is a
  49. different language). '\0' and 0 are thus _identical_ in type and
  50. value, the difference in use is stylistic.
  51.  
  52. Cheers
  53. Tanmoy
  54. --
  55. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  56. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  57. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  58. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  59. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  60. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  61.